package com.hb.trade.server.center.au.manager;

import cn.hutool.core.util.StrUtil;
import com.hb.core.pojo.center.au.dto.RoleDTO;
import com.hb.core.pojo.enums.RoleDataAuthEnum;
import com.hb.core.pojo.enums.RoleSignEnum;
import com.hb.core.pojo.enums.RoleTypeEnum;

/**
 * 角色对象业务处理类
 *
 * @autho zhaojk
 */
public class RoleManager extends RoleDTO {
    /**
     * 获取一个角色对象
     *
     * @param roleName
     * @return
     * @deprecated 无法确定roleType
     */
    @Deprecated
    public static RoleManager get(String roleName) {
        if (StrUtil.isEmpty(roleName)) {
            return new RoleManager();
        }

        RoleManager roleManager = new RoleManager();
        roleManager.setRoleName(roleName);
        roleManager.init();

        return roleManager;
    }

    /**
     * 获取一个角色对象
     *
     * @param roleTypeEnum
     * @return
     */
    public static RoleManager get(Long orgId, Integer roleSign, RoleTypeEnum roleTypeEnum) {
        if (orgId == null || roleSign == null || roleTypeEnum == null) {
            return new RoleManager();
        }

        RoleManager roleManager = new RoleManager();
        roleManager.setRoleName(roleTypeEnum.getShowName());
        roleManager.setRoleType(roleTypeEnum.getCode());
        // 初始化角色数据
        roleManager.init();

        roleManager.buildBaseData(1);
        roleManager.setOrgId(orgId);
        roleManager.setRoleSign(roleSign);

        // 根据角色类型设置数据权限(产品需求定死的)
        switch (roleTypeEnum) {
            case BRANCH_COMPANY_MANAGER:
                roleManager.setRoleDataAuth(RoleDataAuthEnum.CHILD_COMPANY_ONLY.getCode());
                break;
            case DEPT_MANAGER:
                roleManager.setRoleDataAuth(RoleDataAuthEnum.CHILD_DEPT_ONLY.getCode());
                break;
            case PROJECT_MANAGER:
                roleManager.setRoleDataAuth(RoleDataAuthEnum.PERSONAL.getCode());
                break;
            default:
                break;
        }

        return roleManager;
    }
}
